//
//  CommentVC.swift
//  Drop
//
//  Created by zhuxuhong on 2018/3/17.
//  Copyright © 2018年 zhuxuhong. All rights reserved.
//

import UIKit

class CommentVC: UIViewController {
    
    @IBOutlet weak var textView: PlaceTextView!
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
    
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .lightContent
    }
    
	var comment: Comment?
	
	var toUser: User?
	
    override func viewDidLoad() {
        super.viewDidLoad()

		if let user = toUser {
			textView.placeholder = "回复\(user.name): "
		}
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        Typist.shared.on(event: .willChangeFrame) {
			[unowned self] options in
            self.bottomConstraint.constant = options.endFrame.height
            self.keyboardAnimation(duration: options.animationDuration)
        }.on(event: .willHide, do: {
			[unowned self] options in
            self.bottomConstraint.constant = 0
            self.keyboardAnimation(duration: options.animationDuration)
        }).start()
		
		textView.becomeFirstResponder()
    }
	
	override func viewWillDisappear(_ animated: Bool) {
		super.viewWillDisappear(animated)
		
		textView.endEditing(true)
	}
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        app.keyWindow?.endEditing(true)
    }
	
    func keyboardAnimation(duration: TimeInterval) {
    }
    
    @IBAction func send(_ sender: Any){
        dismiss()
    }
    
    deinit {
        Typist.shared.stop()
    }
}
